import React from 'react';
import {getWeiboAsync, useSelectorWeibo} from "../store/slice/weibo";
import {useDispatch} from "react-redux";

function PageList(props) {
    const {pageNo,pageSum,pageSize} = useSelectorWeibo();
    const dispatch = useDispatch();
    const pageArr = [];
    for(let i=1;i<=pageSum;i++){
        pageArr.push(<a key={i} href="" onClick={e=>{
            e.preventDefault();
            dispatch(getWeiboAsync(i,pageSize))
        }} className={pageNo===i?"active":""}>{i}</a>)
    }
    return (
        <div className="page">
            {pageArr}
        </div>
    );
}

export default PageList;